# 导包
import unittest

from api.employee import EmployeeAPI
from utils import coommon_assert

# 创建测试类
class TestEmployeeAPI(unittest.TestCase):
    # 定义员工ID
    employee_id = None
    # 前置处理
    def setUp(self):
        # 实例化接口类
        self.employee_api = EmployeeAPI()

    # 添加员工
    def test01_insert_employee(self):
        insert_data = {
            "username": "jack202017105",
            "mobile": "13201007198",
            "timeOfEntry": "2020-07-09",
            "formOfEmployment": 1,
            "workNumber": "1008601007105",
            "departmentName": "销售",
            "departmentId": "1266699057968001024",
            "correctionTime": "2020-07-30T16:00:00.000Z"}
        response = self.employee_api.insert_employee(insert_data)
        print(response.json())
        # 断言------调用公共方法
        coommon_assert(self, response)

        # 提取员工ID
        TestEmployeeAPI.employee_id = response.json().get("data").get("id")
        print(TestEmployeeAPI.employee_id)

    # 查询员工
    def test02_select_employee(self):
        response = self.employee_api.select_employee(TestEmployeeAPI.employee_id)
        print(response.json())
        # 断言------调用公共方法
        coommon_assert(self, response)

    # 修改员工
    def test03_update_employee(self):
        update_data = {"username": "rrrfff"}
        response = self.employee_api.update_employee(TestEmployeeAPI.employee_id, update_data)
        print(response.json())
        # 断言------调用公共方法
        coommon_assert(self, response)

    # 删除员工
    def test04_delete_employee(self):
        response = self.employee_api.delete_employee(TestEmployeeAPI.employee_id)
        print(response.json())
        # 断言------调用公共方法
        coommon_assert(self, response)

